package com.itboy.mall.pms.product.web;

import com.itboy.common.core.domain.AjaxResult;
import com.itboy.mall.pms.category.domain.MallCategory;
import com.itboy.mall.pms.category.service.IMallCategoryService;
import com.itboy.mall.pms.product.vo.Category2Vo;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Validated
@Api(value = "首页", tags = {"首页管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Controller
public class IndexController {
	private final IMallCategoryService iMallCategoryService;

	@GetMapping(value = {"/","/index.html"})
	public String indexPage(Model model){
		//1. 查询出所有的一级分类
		List<MallCategory> level1MallCategoryList=iMallCategoryService.getLevel1MallCategory();
		model.addAttribute("level1MallCategoryList",level1MallCategoryList);
		return  "index";
	}

	@GetMapping(value = "/index/getCategoryJson")
	@ResponseBody
	public AjaxResult<Map<String, List<Category2Vo>>> getCategoryJson(Model model){
		//1. 查询出所有的一级分类
		Map<String, List<Category2Vo>> category2Vo= iMallCategoryService.getCategoryJson();
		return  AjaxResult.success(category2Vo);
	}
}
